%Reconstruction of Laplacian Pyramid
%Arguments: cell "pyramid", containing the laplacian pyramid of image R

%This function was written after studying T. Mertens', J. Kautz' and 
%F. Van Reeth's implementation of Exposure Fusion
%http://research.edm.uhasselt.be/~tmertens/exposure_fusion/

function R = recon_laplace_pyramid(pyramid)

numL = length(pyramid); %extract number of levels
R = pyramid{numL}; %R contains the smallest level
for i = numL - 1 : -1 : 1 %go backwards from the second smallest level
    odd = 2*size(R) - size(pyramid{i}); %odd is a vector which has 2 values, 
    %indicating whether the future upsampled dimension has to be odd (1) or
    %even (0)
    
    %reconstruct by adding the current level to the upsampled lower level
    R = pyramid{i} + resample2D(R,'up',odd);
end
